// 全局变量
var checkName = function(){
	console.log("验证姓名逻辑");
}
var checkPassword = function(){
	console.log("验证密码");
}

// 用对象收编封装变量
var CheckObject = {
	checkName: function(){
		console.log("验证姓名逻辑");
	},
	checkPassword: function(){
		console.log("验证密码");
	}
}
// 真假对象
var checkObject = function(){
	return {
		checkName: function(){
			console.log("验证姓名逻辑");
		},
		checkPassword: function(){
			console.log("验证密码");
		}
	}
}

// var a = checkObject();
// a.checkName()

// 用类创建

var checkOBJ = function(){
	this.checkName = function(){
		console.log("验证姓名逻辑");
	}
	this.checkPassword = function(){
		console.log("验证密码");
	}
}

// var b = new checkOBJ();
// b.checkName()
// 新创建的对象都会对类的this上的属性进行复制，所以新对象都会有自己的一套方法

var chObj = function(){};
chObj.prototype.checkName = function(){
	console.log("验证姓名逻辑");
}
chObj.prototype.checkPassword = function(){
	console.log("验证密码");
}

// 链式调用
var check = {
	checkName: function(){
		console.log("验证姓名逻辑");
		return this;
	},
	checkPassword: function(){
		console.log("验证密码");
		return this;
	}
}

// check.checkName().checkPassword()

var check2 = function(){}
check2.prototype = {
	checkName: function(){
		console.log("验证姓名逻辑");
		return this;
	},
	checkPassword: function(){
		console.log("验证密码");
		return this;
	}
}

// var b = new check2();
// b.checkName().checkPassword()

Function.prototype.checkName = function(){
	console.log("验证姓名逻辑");
}

var f = function() {}
// f.checkName()

var fn = new Function() // 这里没有{} 容易错
// fn.checkName()
// 别人创建任何函数，被你创建的函数所污染，造成不必要的开销

Function.prototype.addMethod = function(name,fn) {
	this[name] = fn;
}
var methods = new Function();
methods.addMethod('checkName',function(){
	console.log("验证姓名逻辑checkName");
})
// methods.checkName()

// 链式调用改写

var methods2 = function(){}
methods2.addMethod('checkName',function(){
	console.log("验证姓名逻辑checkName");
}).addMethod('checkPassword',function(){
	console.log("验证密码checkPassword");
})

methods2.checkName().checkPassword()